//
//  ViewController.swift
//  RN
//
//  Created by HFY on 2021/1/19.
//

import UIKit

class ViewController: UIViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        LoadBundle.shared

        let btn = UIButton.init(type: .custom)
        btn.addTarget(self, action: #selector(pushRN), for: .touchUpInside)
        btn.frame = CGRect.init(x: (view.frame.width - 60)/2, y: (view.frame.height-40)/2, width: 160, height: 40)
        btn.backgroundColor = UIColor.gray
        view.addSubview(btn)
        btn.setTitle("跳转到完整的RN", for: .normal)
        
        
        let btn1 = UIButton.init(type: .custom)
        btn1.addTarget(self, action: #selector(pushRN1), for: .touchUpInside)
        btn1.frame = CGRect.init(x: (view.frame.width - 60)/2, y: btn.frame.maxY + 30, width: 160, height: 40)
        btn1.backgroundColor = UIColor.gray
        view.addSubview(btn1)
        btn1.setTitle("跳转到只加载基础包的RN", for: .normal)
    }

    @objc func pushRN(){
        do{
            let path = Bundle.main.url(forResource: "buz.ios", withExtension: "bundle")!
            let data = try Data.init(contentsOf: path)
            LoadBundle.shared.bridge?.batched.executeSourceCode(data, sync: true)
        }catch {
            
        }
        let rn = SReactViewController.init(rnName: "App", props: ["scores":
                                                                            [
                                                                                ["name":"Alex", "value":"42"],
                                                                                ["name":"Joel", "value":"10"]
                                                                            ]
                                                                        ])
        rn.debuger.isDebug = true
        navigationController?.pushViewController(rn, animated: true)
    }
    
    @objc func pushRN1(){
        let rn = SReactViewController.init(rnName: "App", props: ["scores":
                                                                            [
                                                                                ["name":"Alex", "value":"42"],
                                                                                ["name":"Joel", "value":"10"]
                                                                            ]
                                                                        ])
        rn.debuger.isDebug = true
        navigationController?.pushViewController(rn, animated: true)
    }
}

